#ifndef ZSINGLETON_H_
#define ZSINGLETON_H_

#include "../Common/GlobalDefines.h"
#include <cassert>

GLOBAL_NAMESPACE_BEGIN

template <class T>
class Singleton
{
private:
	Singleton(const Singleton<T>&);
	Singleton& operator=(const Singleton<T>&);

protected:
	static T* singleton_;

public:
	Singleton(void)
	{
		assert(!singleton_);
		singleton_ = static_cast<T*>(this);
	}

	~Singleton(void)
	{
		assert(singleton_);
		singleton_ = 0;
	}

	static T& getSingleton(void)
	{
		assert(singleton_);
		return (*singleton_);
	}

	static T* getSingletonPtr(void)
	{
		return singleton_;
	}

    virtual void init() {}
};	

GLOBAL_NAMESPACE_END

#endif//ZSINGLETON_H_